package org.jeecg.modules.core.passdata.service.impl;

import org.jeecg.modules.core.passdata.mapper.HighwayReportStatisticsMapper;
import org.jeecg.modules.core.passdata.params.HighwayReportStatisticsParams;
import org.jeecg.modules.core.passdata.service.HighwayReportStatisticsService;
import org.jeecg.modules.core.passdata.vo.HighwayReportStatisticsVo;
import org.jeecg.modules.core.passdata.vo.OverloadHighwayDetailsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HighwayReportStatisticsServiceImpl implements HighwayReportStatisticsService {

    @Resource
    HighwayReportStatisticsMapper highwayReportStatisticsMapper;

    //公路超载数据 月度报表
    @Override
    public List<HighwayReportStatisticsVo> queryPageList(HighwayReportStatisticsParams params) {
        //只有时间止，自动赋值时间起
        //获取所有的区县
        List<HighwayReportStatisticsVo> list = highwayReportStatisticsMapper.getAllRegion();
        //获取区县统计
        List<HighwayReportStatisticsVo> region = highwayReportStatisticsMapper.getRegionAllData(params);
        //获取站点统计
        List<HighwayReportStatisticsVo> site = highwayReportStatisticsMapper.getSiteAllData(params);
        //获取站点详情
        List<OverloadHighwayDetailsVo> detailsVos = highwayReportStatisticsMapper.getOverloadDetails(params);
        for (HighwayReportStatisticsVo si : site) {
            for (OverloadHighwayDetailsVo detail : detailsVos) {
                if (si.getSiCode().equals(detail.getSiCode())) {
                    si.getDetails().add(detail);
                }
            }
        }
        for (HighwayReportStatisticsVo vo : list) {
            for (HighwayReportStatisticsVo reSum : region) {
                if (reSum.getReCode().equals(vo.getReCode())) {
                    vo.setCount(reSum.getCount());
                    vo.setMonSum(reSum.getMonSum());
                }
            }
            for (HighwayReportStatisticsVo siteLi : site) {
                if (siteLi.getReCode().equals(vo.getReCode())) {
                    vo.getChildList().add(siteLi);
                }
            }

        }
        return list;
    }


}
